import java.util.Arrays;

public class Solution1191 {
    public int kConcatenationMaxSum(int[] arr, int k) {
        if (k==1){
            int max=0,t=0;
            for (int i : arr) {
                t=Math.max(t+i,0);
                max=Math.max(max,t);
            }
            return max;
        }
        int sum= Arrays.stream(arr).sum();
        if (sum<=0){
            int max=0,t=0;
            for (int i=0;i<arr.length*2;i++) {
                t=Math.max(t+arr[i%arr.length],0);
                max=Math.max(max,t);
            }
            return max;
        }
        long mod=1000000007;
        long ans= (long)sum*k%mod;
        int max=0,t=0;
        for (int i=0;i<arr.length*2;i++) {
            t=Math.max(t+arr[i%arr.length],0);
            max=Math.max(max,t);
        }
        ans=(ans+max-sum*2+mod)%mod;
        return (int)ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1191().kConcatenationMaxSum(new int[]{1,2},3));
    }
}
